rm(list=ls())
library(ggplot2)

###
### Figure 3.7: Effect of Far-Right Polling on Speeches, Manifestos, and Inquiries
### (using coefficients and SEs from other scripts)
###

party <- rep(c("CDU", "AfD", "FDP", "Greens", "Left", "SPD"), 5)
coef <- c(0.0426903403, 0.0361015659, -0.0009548151, 0.1233833817, 0.0972381303, 0.0830687942,
          0.0353113462, 0.0184830300, -0.0170121924, 0.1207894854, 0.0978417500, 0.0828261110,
          -0.03985683, 0.05110355, -0.03526890, 0.05693105, 0.04682542, 0.06889661,
          -0.06816228, 0.01503065, -0.05652807, 0.02597598, 0.01483627, 0.03370358,
          0.025827870, 0.002789278, 0.048436198, 0.015107572, 0.004568898, -0.034188047)
se <- c(0.03612570, 0.14780887, 0.04124452, 0.03669977, 0.03970607, 0.03612466,
        0.03882497, 0.15641566, 0.04437423, 0.03897458, 0.04208162, 0.03883320,
        0.04406475, 0.05852100, 0.04405133, 0.04427604, 0.04602665, 0.04411527,
        0.04745966, 0.06264427, 0.04745626, 0.04752721, 0.04933225, 0.04751839,
        0.007273000, 0.005417590, 0.015221643, 0.004211672, 0.003507173, 0.008230653)
outcome <- rep(c("Speeches: Position", "Speeches: Bias", "Manifestos: Position", "Manifestos: Bias", "Inquiries"), each=6)
outcome <- factor(outcome, levels=c("Speeches: Position", "Speeches: Bias", "Manifestos: Position", "Manifestos: Bias", "Inquiries"))
polling <- data.frame(party,coef,se,outcome)

pdf("Fig3_7.pdf", width = 10.5, height=7.5)
ggplot(data=polling, aes(x=party, y=coef, group=factor(outcome), shape=factor(outcome))) + 
  geom_point(position=position_dodge2(0.5), size=2.5) + 
  geom_errorbar(aes(ymax=coef+1.96*se, ymin=coef-1.96*se), width=0, position=position_dodge(0.5), group=factor("party")) +
  theme_bw() + 
  geom_hline(yintercept = 0, linetype="dashed") +
  theme(legend.position = "bottom", text = element_text(size=18), panel.grid = element_blank()) +
  xlab("") + 
  ylab("Marginal Effect of\nFar-Right Polling") +
  scale_shape_manual(values=c(15, 16, 17, 18, 4), name="")
dev.off()